home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / hypercrd / hc2_x / tcprogud.sit / TC Prog Guide / card_28872.txt < prev    next >
Text File  |  1991-02-27  |  1KB  |  24 lines

  1. -- card: 28872 from stack: in
  2. -- bmap block id: 0
  3. -- flags: 0000
  4. -- background id: 4755
  5. -- name: 
  6.  
  7.  
  8. -- part contents for background part 4
  9. ----- text -----
  10. It is possible to override the default storage class for local variables (automatic) by using the 'static' storage class specifier:
  11.  
  12.     static int  cumulative_sum;
  13.  
  14. Such a variable retains its previous value during subsequent function calls.  If an initialization is provided, it is assigned only the first time the function is called.
  15.  
  16. Confusingly, the 'static' specifier can also be applied to identifiers (variables, functions, type definitions) having file scope.  In this case, the storage class is not affected (since such variables are always static and functions and type definitions have no storage class) but it is no longer possible to access the identifier from other source files.  (In effect, the scope has been restricted to a single file only.)
  17.  
  18. This technique is often useful to organize a program into several source files, each of which has a restricted and well-defined interface with the other source files.  An alternative approach for obtaining such modularity is provided by the object-oriented features of TC and C++ discussed in Chapter 4.
  19.  
  20.  
  21.  
  22. -- part contents for background part 7
  23. ----- text -----
  24. 79